#include <GLFW/glfw3.h>

#include "cursor.hpp"
#include "window.hpp"

float carbon::C_Cursor::xpos, carbon::C_Cursor::ypos;
float carbon::C_Cursor::deltaX, carbon::C_Cursor::deltaY;
bool  carbon::C_Cursor::started;
carbon::CursorLockMode carbon::C_Cursor::lockState;

int carbon::C_Cursor::initialize() {
    centerPosition();
    return 0;
}

// returns rounded cursor position without floating point
int *carbon::C_Cursor::getPosNormalized() {
    int p[2] = {static_cast<int>(xpos), static_cast<int>(ypos)};
    return p;
}

// sets cursor position to window's center
void carbon::C_Cursor::centerPosition() {
    int w, h;
    glfwGetWindowSize(carbon::C_Window::_window, &w, &h);

    int hw = w / 2, hh = h / 2;

    glfwSetCursorPos(
        carbon::C_Window::_window,
        static_cast<double>(hw),
        static_cast<double>(hh));
}

// sets cursor position to the top-left corner of the window
void carbon::C_Cursor::resetPosition() {
    glfwSetCursorPos(carbon::C_Window::_window, 0, 0);
}